//
//  ToolHelper.m
//  一起自驾游
//
//  Created by apple-CXTX on 17/12/12.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ToolHelper.h"

@implementation ToolHelper

+ (void)notifyError:(NSString *)msg
{
    [self showPrompt:msg];
}

//提示框
+(void)showPrompt:(NSString *)message
{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(50, SCREEN_HEIGHT/3 - 15, SCREEN_WIDTH - 100, 30)];
    view.backgroundColor = [UIColor colorWithRed:52/255.f green:52/255.f blue:52/255.f alpha:1.f];
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius = 8.0f;
    UILabel  *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, view.bounds.size.width-10, 40)];
    label.numberOfLines = 0;
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15];
    label.textAlignment = NSTextAlignmentCenter;
    
    CGFloat  laHight = [self calculateLabSizeLabelText:message font:label.font size:label.frame.size].height;
    
    label.frame = CGRectMake(5, 5, view.bounds.size.width-10, laHight);
    view.frame = CGRectMake(50, SCREEN_HEIGHT/2 - label.frame.size.height/2, SCREEN_WIDTH - 100, label.frame.size.height+10);
    [view addSubview:label];
    
    //window.windowLevel = UIWindowLevelAlert;
    [window addSubview:view];
    window.userInteractionEnabled = NO;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),dispatch_get_main_queue(), ^{//N秒以后移除view
        window.userInteractionEnabled = YES;
        [view removeFromSuperview];
        //            window.windowLevel = UIWindowLevelNormal;
    });
}

+ (CGSize )calculateLabSizeLabelText: (NSString *)text font:(UIFont *)font size:(CGSize)size {
    
    CGSize titleSize = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
    
    return titleSize;
    
}

/**
 *计算overlay时间的距离
 *param:为飞行器高度
 */
+ (CGFloat)outPutCammeraPicLength:(CGFloat)airCraftH {
    CGFloat H = airCraftH;
    double m =  H * tan((42) / 180.0 * M_PI);
    NSLog(@"m----%f",m);
    
    return m;
}



+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString
{
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err)
    {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

+ (BOOL)judgeStr:(NSString *)str1 with:(NSString *)str2

{
    
    int a=[str1 intValue];
    
    double s1=[str2 doubleValue];
    
    int s2=[str2 intValue];
    
    
    
    if (s1/a-s2/a>0) {
        
        return NO;
        
    }
    
    return YES;
    
}

@end

